package com.shiguiwu.springmybatis.javabase.generics;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @description: 根据匿名内部诶
 * @author: stone
 * @date: Created by 2021/3/12 15:23
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.generics
 */
public class GenericsClassSuper<K, V> {


    public void test(GenericsClassSuper<K, V> genericsClassSuper) {
        //demo6Class对应的是Demo6的Class对象
        Class<? extends GenericsClassSuper> clazz = genericsClassSuper.getClass();
        //获取genericsClassSuper的父类的详细类型信息，包含泛型信息
        Type genericSuperclass = clazz.getGenericSuperclass();
        // 泛型类型用ParameterizedType接口表示，输出看一下是不是这个接口类型的
        System.out.println(genericSuperclass.getClass());
        if (genericSuperclass instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) genericSuperclass;
            System.out.println(pt.getRawType());
            Type[] actualTypeArguments = pt.getActualTypeArguments();
            for (Type actualTypeArgument : actualTypeArguments) {
                System.out.println(actualTypeArgument.getTypeName());
            }
            System.out.println(pt.getOwnerType());
        }
    }

    public static void main(String[] args) {
        GenericsClassSuper<String, Integer> k = new GenericsClassSuper<String, Integer>() {
        };
        k.test(k);
    }
}
